'''
已知某节目采用计票机制,选手获得的票数越多,排名就越靠前.
要求编写程序,接收选手的姓名和票数,输出排序后的成绩
'''
counter1 = 0
counter2 = 0
counter3 = 0
disc_score = {'张三':0,'李四':0,'王五':0}
li = []
while True:
    print('选手编号:','1.张三','2.李四','3.王五','0.统计完成,退出计票')
    x = int(input('请输入你要投票的选手编号:'))
    if x == 1:
        counter1 += 1
        disc_score['张三'] = counter1
        print(disc_score)
    if x == 2:
        counter2 += 1
        disc_score['李四'] = counter2
        print(disc_score)
    if x == 3:
        counter3 += 1
        disc_score['王五'] = counter3
        print(disc_score)
    if x == 0:
        break
items = disc_score.items()
for j in items:
    li.append([j[1],j[0]])
li.sort()
print(li)
count = len(li) - 1
for i in range(1,len(li) + 1):
    print(f'第{i}名选手姓名:{li[count][1]},得票数为{li[count][0]}')
    count -= 1


# player_info = {}
# li = []
# print('输入quit表示选手成绩录入完毕')
# while True:
#     name = input('请输入选手姓名:')
#     if name == 'quit':
#         break
#     score = int(input('请输入选手得票数:'))
#     player_info[name] = score
# items = player_info.items()
# for j in items:
#     li.append([j[1],j[0]]) # 将可以用于排序的整型放在前面
# print(li)
# # 转换为list类型进行排序
# li.sort()
# # 获取选手索引
# count = len(li) - 1
#     # 输出排名
# for i in range(1,len(li) + 1):
#         print(f'第{i}名:{li[count][1]},成绩为{li[count][0]}分')
#         count -= 1

